package cn.htsyb.synergy.security.bean.param;

import cn.htsyb.synergy.orm.jpa.criterion.ExpressBuilder;
import cn.htsyb.synergy.orm.jpa.criterion.QueryExpress;
import cn.htsyb.synergy.orm.jpa.model.param.AbsStandardParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.List;
/**
 * 组织 参数类
 * codeMaker at 2020-07-14
 * @author lakeside hubin_yuan.410@hotmail.com
 * @since 2020-07-14
 */
@Setter
@Getter
@Schema(description = "组织参数")
public class SecurityOrganizeParam extends AbsStandardParam {
    /**层级名称*/
    @Schema(name = "layerName", description = "层级名称 ")
    protected  String layerName;
    /**层级*/
    @Schema(name = "level", description = "层级 ")
    protected  Integer level;
    /**模型*/
    @Schema(name = "model", description = "模型 ")
    protected  String model;
    /**名称*/
    @Schema(name = "name", description = "名称 ")
    protected  String name;
    /**上级主键*/
    @Schema(name = "parentId", description = "上级主键 ")
    protected  String parentId;
    /**领导者*/
    @Schema(name = "leaderId", description = "领导者 ")
    protected  String leaderId;
    /**管理者*/
    @Schema(name = "managerId", description = "管理者 ")
    protected  String managerId;

    /**通用过滤*/
    @Schema(name = "filter", description = "通用过滤")
    protected String filter;

    @Override
    public List<QueryExpress> searchCriterion() {
        return ExpressBuilder.instance(super.searchCriterion())
                    .addExpressOfOperator(!StringUtils.isEmpty(layerName), "layerName", QueryExpress.Operator.EQ, layerName)
                    .addExpressOfOperator(!ObjectUtils.isEmpty(level), "level", QueryExpress.Operator.EQ, level)
                    .addExpressOfOperator(!StringUtils.isEmpty(model), "model", QueryExpress.Operator.EQ, model)
                    .addExpressOfOperator(!StringUtils.isEmpty(name), "name", QueryExpress.Operator.EQ, name)
                    .addExpressOfOperator(!StringUtils.isEmpty(parentId), "parentId", QueryExpress.Operator.EQ, parentId)
                    .addExpressOfOperator(!StringUtils.isEmpty(leaderId), "leaderId", QueryExpress.Operator.EQ, leaderId)
                    .addExpressOfOperator(!StringUtils.isEmpty(managerId), "managerId", QueryExpress.Operator.EQ, managerId)
                .build();
    }

    @Override
    public List<QueryExpress> filterCriterion() {
        boolean bool=!StringUtils.isEmpty(filter);

        return ExpressBuilder.instance(super.filterCriterion())
                /*需要自行根据索引调整可支持的通用查询字段，切不可全字段通用查询
                .addExpressOfOperator(bool,"layerName",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"model",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"name",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"parentId",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"leaderId",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"managerId",QueryExpress.Operator.LIKE, filter)
                 */
                .build();
    }
}